// ==UserScript==
// @name         批量打开待办文件
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://oa.yuxi.cn/OA/LEAP/Login/5304/BOA/*
// @icon         http://oa.yuxi.cn/OA/LEAP/LBCPSYS1Module/Index/img/gongwen.png
// @grant        none
// ==/UserScript==

function openLinks() {
    const ul = document.querySelector(
        "#LEAPLGRES_ID_1 > ul > li:nth-child(4) > div.drag_ul_li_chart > div > div > div > div.lbcpcontent_module-content > ul:nth-child(2)",
    );
    console.log("nimei", ul);
    for (const a of ul.children) {
        console.log("c", a.children[2]);
        a.children[2].click();
    }
}

function addDownloadButton() {
    //const bottomButtons = document.querySelector("body > div.ZHBG_page > div.lg_p_lr_fill > div > div.ZHBG_content.lg_p_lr_fill > div > div.ZHBG_add-router.lg_p2_tb_top")

    const targetPos = document.querySelector(
        "#LEAPLGRES_ID_1 > ul > li:nth-child(5) > div.drag_ul_li_chart > div > div > table > tbody > tr > td > div > ul",
    );

    console.log("find", targetPos);
    if (!targetPos) {
        return;
    }
    let downloadButton = document.createElement("button");
    downloadButton.setAttribute("id", "copy-text-button");
    downloadButton.setAttribute("class", "root-198 my-2");

    downloadButton.type = "button";
    downloadButton.textContent = "打开";

    downloadButton.addEventListener("click", openLinks);

    targetPos.appendChild(downloadButton);
    downloadButton = null; //及时解除不再使用的变量引用,即将其赋值为 null;
}

(function () {
    "use strict";

    // Your code here...

    setTimeout(() => {
        addDownloadButton();
    }, 3000);
})();
